/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateMountpoint
/*     */   extends RedoableOp
/*     */ {
/*     */   private int mId;
/*     */   private String mUuid;
/*     */   private int mFolderId;
/*     */   private String mName;
/*     */   private String mOwnerId;
/*     */   private int mRemoteId;
/*     */   private String mRemoteUuid;
/*     */   private MailItem.Type defaultView;
/*     */   private int mFlags;
/*     */   private long mColor;
/*     */   private boolean mReminderEnabled;
/*     */   
/*     */   public CreateMountpoint()
/*     */   {
/*  48 */     super(MailboxOperation.CreateMountpoint);
/*  49 */     this.mId = 0;
/*     */   }
/*     */   
/*     */   public CreateMountpoint(int mailboxId, int folderId, String name, String ownerId, int remoteId, String remoteUuid, MailItem.Type view, int flags, Color color, boolean reminderEnabled)
/*     */   {
/*  54 */     this();
/*  55 */     setMailboxId(mailboxId);
/*  56 */     this.mId = 0;
/*  57 */     this.mFolderId = folderId;
/*  58 */     this.mName = (name != null ? name : "");
/*  59 */     this.mOwnerId = ownerId;
/*  60 */     this.mRemoteId = remoteId;
/*  61 */     this.mRemoteUuid = remoteUuid;
/*  62 */     this.defaultView = view;
/*  63 */     this.mFlags = flags;
/*  64 */     this.mColor = color.getValue();
/*  65 */     this.mReminderEnabled = reminderEnabled;
/*     */   }
/*     */   
/*     */   public int getId() {
/*  69 */     return this.mId;
/*     */   }
/*     */   
/*     */   public String getUuid() {
/*  73 */     return this.mUuid;
/*     */   }
/*     */   
/*     */   public void setIdAndUuid(int id, String uuid) {
/*  77 */     this.mId = id;
/*  78 */     this.mUuid = uuid;
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  83 */     StringBuilder sb = new StringBuilder("id=").append(this.mId);
/*  84 */     sb.append(", uuid=").append(this.mUuid);
/*  85 */     sb.append(", name=").append(this.mName).append(", folder=").append(this.mFolderId);
/*  86 */     sb.append(", owner=").append(this.mOwnerId).append(", remoteId=").append(this.mRemoteId).append(", remoteUuid=").append(this.mRemoteUuid);
/*  87 */     sb.append(", view=").append(this.defaultView).append(", flags=").append(this.mFlags).append(", color=").append(this.mColor);
/*  88 */     sb.append(", reminder=").append(this.mReminderEnabled);
/*  89 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/*  94 */     out.writeInt(this.mId);
/*  95 */     if (getVersion().atLeast(1, 37)) {
/*  96 */       out.writeUTF(this.mUuid);
/*     */     }
/*  98 */     out.writeUTF(this.mName);
/*  99 */     out.writeUTF(this.mOwnerId);
/* 100 */     out.writeInt(this.mRemoteId);
/* 101 */     if (getVersion().atLeast(1, 38)) {
/* 102 */       out.writeUTF(this.mRemoteUuid);
/*     */     }
/* 104 */     out.writeInt(this.mFolderId);
/* 105 */     out.writeByte(this.defaultView.toByte());
/* 106 */     out.writeInt(this.mFlags);
/* 107 */     out.writeLong(this.mColor);
/* 108 */     out.writeBoolean(this.mReminderEnabled);
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/* 113 */     this.mId = in.readInt();
/* 114 */     if (getVersion().atLeast(1, 37)) {
/* 115 */       this.mUuid = in.readUTF();
/*     */     }
/* 117 */     this.mName = in.readUTF();
/* 118 */     this.mOwnerId = in.readUTF();
/* 119 */     this.mRemoteId = in.readInt();
/* 120 */     if (getVersion().atLeast(1, 38)) {
/* 121 */       this.mRemoteUuid = in.readUTF();
/*     */     }
/* 123 */     this.mFolderId = in.readInt();
/* 124 */     this.defaultView = MailItem.Type.of(in.readByte());
/* 125 */     this.mFlags = in.readInt();
/* 126 */     if (getVersion().atLeast(1, 27)) {
/* 127 */       this.mColor = in.readLong();
/*     */     } else {
/* 129 */       this.mColor = in.readByte();
/*     */     }
/* 131 */     if (getVersion().atLeast(1, 33)) {
/* 132 */       this.mReminderEnabled = in.readBoolean();
/*     */     }
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 138 */     int mboxId = getMailboxId();
/* 139 */     Mailbox mailbox = MailboxManager.getInstance().getMailboxById(mboxId);
/*     */     try
/*     */     {
/* 142 */       mailbox.createMountpoint(getOperationContext(), this.mFolderId, this.mName, this.mOwnerId, this.mRemoteId, this.mRemoteUuid, this.defaultView, this.mFlags, Color.fromMetadata(this.mColor), this.mReminderEnabled);
/*     */     }
/*     */     catch (MailServiceException e) {
/* 145 */       if (e.getCode() == "mail.ALREADY_EXISTS") {
/* 146 */         if (mLog.isInfoEnabled()) {
/* 147 */           mLog.info("Mount " + this.mId + " already exists in mailbox " + mboxId);
/*     */         }
/*     */       } else {
/* 150 */         throw e;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/CreateMountpoint.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */